<template>
  <el-dialog
    :title="showDetail ? $t('agv.taskDetails') : $t('agv.createTasks')" v-model="visible"
    :width="showDetail ? '70%' : '80%'" draggable :close-on-click-modal="false"
    style="font-size: large;margin-top: 20px">
    <template #title>
        <span>
          <span v-if="showDetail"><i class="iconfont icon-xiangqing mr-2 color5"></i>{{ $t('agv.taskDetails') }}</span>
          <span v-else><i class="iconfont icon-edit-rep mr-2 color3"></i>{{$t('agv.createTasks')}}</span>
        </span>
    </template>
    <el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef v-loading="loading"
      label-width="130px" label-position="right" style="margin-bottom: 30px" v-if="!showDetail">
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item :label="$t('agv.taskType')" prop="businessTaskType" label-width="auto">
            <el-select :placeholder="$t('agv.taskType')" filterable clearable remote @change="getTaskTypeClick"
              :remote-method="getProcessList" v-model="form.businessTaskType">
              <el-option v-for="item in processList" :key="item.itemValue" :label="item.itemValue" :value="item">
                <span style="float: left">{{ item.itemText }}</span>
                <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px"> {{
                    item.itemValue
                  }} </span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('agv.priority')" prop="initPriority" label-width="auto">
            <el-select v-model="form.initPriority" @change="selectInitPriority" clearable>
              <el-option v-for="item in priorityList" :key="item.id" :label="item.id" :value="item.name"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('agv.scanType')" prop="scanType" label-width="auto">
            <el-select v-model="form.scanType" @change="selectScanType" clearable>
              <el-option v-for="item in scanTypeList" :key="item.id" :label="item.name" :value="item.id"/>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-card style="max-width: 100%;padding: 0!important;" class="box-card" v-if="showDetail">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.taskNo') }}：</el-text>
          <span>{{ detailData.taskCode }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col>
          <el-text>{{ $t('agv.taskType') }}：</el-text>
          <span>{{ detailData.businessTaskTypeName }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col>
          <el-text>{{ $t('agv.taskStatus') }}：</el-text>
          <el-tag type="primary">{{ detailData.taskStatusStr }}</el-tag></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.scanType') }}：</el-text>
          <span>{{ detailData.scanType }}</span></el-col>
        <el-col :span="12">
          <el-text>{{ $t('agv.agvNo') }}：</el-text>
          <el-tag type="info">{{ detailData.robotCode }}</el-tag></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.palletNo') }}：</el-text>
          <span>{{ detailData.cartonNo }}</span></el-col>
        <el-col :span="12">
          <el-text>{{ $t('agv.palletType') }}：</el-text>
          <span>{{ detailData.cartonType }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.transportedQty') }}：</el-text>
          <el-tag type="success">{{ detailData.qty }}</el-tag></el-col>
        <el-col :span="12">
          <el-text>{{ $t('agv.priority') }}：</el-text>
          <el-tag type="warning">{{ detailData.initPriority }}</el-tag></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.pick-upLocation') }}：</el-text>
          <span>{{ detailData.fromLocationName }}</span></el-col>
        <el-col :span="12">
          <el-text>{{ $t('agv.unloadingPosition') }}：</el-text>
          <span>{{ detailData.toLocationName }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.unloadingPositionQty') }}：</el-text>
          <el-tag type="success">{{ detailData.existQty }}</el-tag></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.materialCode') }}：</el-text>
          <span>{{ detailData.materialCode }}</span></el-col>
        <el-col :span="12">
          <el-text>{{ $t('agv.materialName') }}：</el-text>
          <span>{{ detailData.materialName }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-text>{{ $t('agv.creationTime') }}：</el-text>
          <span>{{ detailData.createTime }}</span></el-col>
        <el-col :span="12">
          <el-text>{{ $t('agv.completionTime') }}：</el-text>
          <span>{{ detailData.taskCompleteTime }}</span></el-col>
      </el-row>
      <el-row :gutter="20" v-if="isWait">
        <el-col :span="20" style="text-align: center; margin-top: 5px">
          <el-button size="default" style="color: #fff; background-color: #c8c9cc" @click="handleCancel">
            {{ $t('agv.cancelTask') }}
          </el-button>
          <el-button size="default" style="color: #fff; background-color: #e6a23c" @click="handleLocation">{{
              $t('agv.changDestination')
            }}
          </el-button>
          <el-button size="default" style="color: #fff; background-color: #c3ac33" @click="handleChangePriority">{{
              $t('agv.changePriority')
            }}
          </el-button>
        </el-col>
      </el-row>
    </el-card>
    <!--创建任务的表格-->
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card class="w-full h-full p-3" shadow="always" >
          <template #header>
            <div class="card-header">
              <span>{{$t('agv.operationType')}}：{{$t('agv.deliveryGoods')}}</span>
            </div>
          </template>
          <el-form ref="dataFormRef2" :rules="dataRules2" label-width="auto" :label-position="'left'"
                   :model="tableList[0]" style="margin-bottom: 30px" size="default">
            <el-form-item :label="$t('agv.process')" prop="processCode" label-width="auto">
              <el-select
                v-model="tableList[0].processCode" @click="getRuleList(tableList[1], '1')" @change="getRuleClick(tableList[1])"
                filterable clearable :remote="true" :disabled="showDetail">
                <el-option v-for="item in perationList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">{{ item.code }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.productionLine')" prop="lineCode" label-width="auto">
              <el-select v-model="tableList[0].lineCode" @click="getRuleList(tableList[0], '2')" filterable clearable :remote="true" :disabled="showDetail">
                <el-option v-for="item in tableList[0].lineList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">
										{{ item.code }}
									</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.position')" prop="locationCode" label-width="auto">
              <el-select
                v-model="tableList[0].locationCode" @click="getRuleList(tableList[0], '3')" @change="getRuleClick(tableList[0], '3')"
                filterable clearable :disabled="showDetail" :remote="true">
                <el-option v-for="item in tableList[0].locationList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">{{ item.code }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.pointPosition')" prop="code" label-width="auto">
              <el-select v-model="tableList[0].code" filterable clearable :remote="true" :disabled="showDetail">
                <el-option v-for="item in tableList[0].locationList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">{{ item.code }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.operationType')"  label-width="auto">
              <el-select v-model="tableList[0].operation" clearable :disabled="showDetail">
                <el-option :label="$t('agv.deliveryGoods')" value="COLLECT"></el-option>
                <el-option :label="$t('agv.releaseGoods')" value="DELIVERY"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.goodsType')" prop="wareType" label-width="auto">
              <el-select v-model="tableList[0].wareType" prop="wareType" clearable :disabled="showDetail">
                <el-option v-for="item in createTaskType" :key="item.text" :label="item.text" :value="item.value">
                  <span>{{ item.text }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.qty')" prop="qty" label-width="auto" >
              <el-input-number class="w-full" v-model="tableList[0].qty" clearable :controls="false" :disabled="showDetail"></el-input-number>
            </el-form-item>
            <el-form-item :label="$t('agv.destinationsQty')" prop="currentQty" label-width="auto" >
              <el-input-number class="w-full" v-model="tableList[0].currentQty" clearable :controls="false" :disabled="showDetail"></el-input-number>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>

      <el-col :span="12">
        <el-card class="w-full h-full p-3" shadow="always">
          <template #header>
            <div class="card-header">
              <span>{{$t('agv.operationType')}}：{{$t('agv.releaseGoods')}}</span>
            </div>
          </template>
          <el-form ref="dataFormRef3" :rules="dataRules3" label-width="auto" :label-position="'left'" :model="tableList[1]"
                   style="margin-bottom: 30px" size="default">
            <el-form-item :label="$t('agv.process')" prop="processCode" label-width="auto" >
              <el-select v-model="tableList[1].processCode" @click="getRuleList(tableList[1], '1')" :disabled="showDetail"
                         @change="getRuleClick(tableList[1])" filterable clearable :remote="true">
                <el-option v-for="item in perationList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">{{ item.code }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.productionLine')" prop="lineCode" label-width="auto" >
              <el-select v-model="tableList[1].lineCode" @click="getRuleList(tableList[1], '2')" filterable clearable :remote="true" :disabled="showDetail">
                <el-option v-for="item in tableList[1].lineList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">
										{{ item.code }}
									</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.position')" prop="locationCode" label-width="auto" >
              <el-select v-model="tableList[1].locationCode" filterable @click="getRuleList(tableList[1], '3')" :disabled="showDetail"
                         @change="getRuleClick(tableList[1], '3')" clearable :remote="true">
                <el-option v-for="item in tableList[1].locationList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">{{ item.code }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.pointPosition')" prop="code" label-width="auto" >
              <el-select v-model="tableList[1].code" filterable clearable :remote="true" :disabled="showDetail">
                <el-option v-for="item in tableList[1].locationList" :key="item.id" :label="item.code" :value="item.code">
                  <span style="float: left">{{ item.text }}</span>
                  <span style="float: right; color: var(--el-text-color-secondary); font-size: 13px">{{ item.code }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.operationType')" label-width="auto" >
              <el-select v-model="tableList[1].operation" clearable :disabled="showDetail">
                <el-option :label="$t('agv.deliveryGoods')" value="COLLECT"></el-option>
                <el-option :label="$t('agv.releaseGoods')" value="DELIVERY"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.goodsType')" prop="wareType" label-width="auto" >
              <el-select v-model="tableList[1].wareType" prop="wareType" clearable :disabled="showDetail">
                <el-option v-for="item in createTaskType" :key="item.text" :label="item.text" :value="item.value">
                  <span>{{ item.text }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('agv.qty')" prop="qty" label-width="auto" >
              <el-input-number class="w-full"  v-model="tableList[1].qty" clearable :controls="false" :disabled="showDetail"></el-input-number>
            </el-form-item>
            <el-form-item :label="$t('agv.destinationsQty')" prop="currentQty" label-width="auto" >
              <el-input-number class="w-full"  v-model="tableList[1].currentQty" clearable :controls="false" :disabled="showDetail"></el-input-number>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
    <template #footer>
      <div class="dialog-footer">
        <el-button icon="Edit" v-if="changeLocation" size="large" @click="handleChange">{{ $t('agv.changDestination') }}</el-button>
        <el-button icon="Edit" type="success" v-if="!showDetail" @click="handleCreateClick" size="large">
          {{ $t('agv.submit') }}
        </el-button>
        <el-button  type="info" @click="handleCancelClick" size="large"> <i class="iconfont icon-huigun mr-2"></i> {{ $t('agv.cancel') }}</el-button>
      </div>
    </template>
    <changePriority ref="changePriorityRef"></changePriority>
  </el-dialog>
</template>

<script setup>
import { ref, reactive, inject, defineExpose,defineAsyncComponent } from 'vue'
import {
  cancelTaskByTaskCode,
  createTask,
  fetchProcess,
  fetchTaskDetail,
  fetchTaskType,
  modifyTaskLocation
} from '@/api/mes/agv'
import { useMessage } from '@/hooks/message'
import useI18n from '@/hooks/language'
const { t } = useI18n();

const changePriority = defineAsyncComponent(() => import('./changePriority.vue'))
const getdataList = inject('getdataList')
// 定义变量内容
const dataFormRef = ref()
const dataFormRef2 = ref();
const dataFormRef3 = ref();
const changePriorityRef = ref()
const visible = ref(false)
const loading = ref(false)
const showDetail = ref(false)
const isWait = ref(false)
const changeLocation = ref(false)
const detailData = ref(null)
// const detailList = ref([]);
const processList = ref([]) //任务类型列表
const perationList = ref([]) //工序列表
const createTaskType = ref([
  //货物类型列表
  {
    text: 'WoodCarton60',
    value: 'WoodCarton60',
  },
  {
    text: 'SteelCarton60',
    value: 'SteelCarton60',
  },
  {
    text: 'SteelCarton48',
    value: 'SteelCarton48',
  },
  {
    text: 'WoodCarton48',
    value: 'WoodCarton48',
  },
])
let tableList = ref([
  {
    id: 0,
    edit: false,
    seq: 0,
    code: '', //点位
    processCode: '', //工序code
    processName: '', //工序名称
    lineCode: '',
    lineName: '',
    locationCode: '',
    locationName: '',
    operation: 'COLLECT', //操作类型
    wareType: '', //货物类型
    currentQty: 0, //数量
    qty: 1, //目的地存在数量
    lineList: [], //产线列表
    locationList: [], //位置列表
  },
  {
    id: 1,
    edit: false,
    seq: 1,
    code: '',
    processCode: '',
    processName: '',
    lineCode: '',
    lineName: '',
    locationCode: '',
    locationName: '',
    operation: 'DELIVERY',
    wareType: '',
    currentQty: 0,
    qty: 1,
    lineList: [],
    locationList: [],
  },
]) //表格数据
// 提交的表单数据
const form = reactive({
  businessTaskType: '', //任务类型
  businessTaskTypeName: '', //任务名称
  initPriority: 0, //优先级
  cartonNo: '', //托盘号
  outputNo: '', //产出编号
  materialCode: '', //物料代码
  materialName: '', //物料名称
  scanType: '', //扫描类型
  cartonType: '', //货物类型
  createUserName: '', //用户名称
  lastModifyUserName: '',
  createBy: '', //用户工号
  createUserNo: '',
  lastModifyUserNo: '',
  listSteps: [],
})
const priorityList = reactive([
  //优先级列表
  {
    id: 1,
    name: 1,
  },
  {
    id: 2,
    name: 2,
  },
  {
    id: 3,
    name: 3,
  },
  {
    id: 4,
    name: 4,
  },
  {
    id: 5,
    name: 5,
  },
])
const scanTypeList = reactive([
  //扫描类型列表
  {
    name: t('agv.noScan'),
    id: 'PICK',
  },
  {
    name: t('agv.putScan'),
    id: 'PUT',
  },
  {
    name: t('agv.pickScan'),
    id: 'NO',
  },
])
// 表单校验规则
const dataRules = reactive({
  businessTaskType: [{
    required: true,
    message: t('agv.taskTypeNotNull'),
    trigger: 'blur'
  }],
  initPriority: [
    {
      required: true,
      message: t('agv.priorityNotNull'),
      trigger: 'change',
    },
  ],
  scanType: [
    {
      required: true,
      message: t('agv.scanTypePlease'),
      trigger: 'change',
    },
  ],
})

const dataRules2 = reactive({
  processCode: [{ required: true, message: t('agv.process'), trigger: 'change' }],
  lineCode: [{ required: true, message: t('agv.productionLine'), trigger: 'change' }],
  locationCode: [{ required: true, message: t('agv.position'), trigger: 'change' }],
  code: [{ required: true, message: t('agv.pointPosition'), trigger: 'blur' }],
  wareType: [{ required: true, message: t('agv.goodsType'), trigger: 'change' }],
});
const dataRules3 = reactive({
  processCode: [{ required: true, message: t('agv.process'), trigger: 'change' }],
  lineCode: [{ required: true, message: t('agv.productionLine'), trigger: 'change' }],
  locationCode: [{ required: true, message: t('agv.position'), trigger: 'change' }],
  code: [{ required: true, message: t('agv.pointPosition'), trigger: 'blur' }],
  wareType: [{ required: true, message: t('agv.goodsType'), trigger: 'change' }],
});
const submitForm = async (formEl, formEl2, formEl3) => {
  if (!formEl) return;
  if (!formEl2) return;
  if (!formEl3) return;
  let b = await formEl2.validate((valid) => {
    if (!valid) {
      return false;
    } else {
      return true;
    }
  });
  let c = await formEl3.validate((valid) => {
    if (!valid) {
      return false;
    } else {
      return true;
    }
  });
  let a = await formEl.validate((valid) => {
    if (!valid) {
      return false;
    } else {
      return true;
    }
  });
  if (a && b && c) {
    form.cartonType = tableList.value[0].wareType ? tableList.value[0].wareType : tableList.value[1].wareType;
    const queryForm = {
      businessTaskType: form.businessTaskType,
      businessTaskTypeName: form.businessTaskTypeName,
      initPriority: form.initPriority,
      cartonNo: form.cartonNo == '' ? null : form.cartonNo,
      outputNo: form.outputNo,
      scanType: form.scanType,
      cartonType: form.cartonType,
      listSteps: [],
    };
    queryForm.listSteps = tableList.value.map((item) => {
      return {
        code: item.code,
        processCode: item.processCode,
        lineCode: item.lineCode,
        locationCode: item.locationCode,
        seq: item.seq,
        operation: item.operation,
        wareType: item.wareType,
        qty: item.qty,
        currentQty: item.currentQty,
        processName: item.processName,
        lineName: item.lineName,
        locationName: item.locationName,
      };
    });
    createTask(queryForm).then((res) => {
      if (res.code === 400) {
        useMessage().warning(res.message);
        // useMessage().warning(t('agv.processNotNull'));
      } else if (res.code === 200) {
        useMessage().success(res.message);
        handleCancelClick();
      }
    });
  }
};

// 校验 状态的选择事件
const select = (e) => {
  form.selectId = e?.id
}
// 扫码类型选择
const selectScanType=(e)=>{
  form.scanType=e
}
// 优先级选择
const selectInitPriority=(e)=>{
  form.initPriority=e
}
// 获取任务类型列表
const getProcessList = () => {
  fetchTaskType({}).then((res) => {
    processList.value = res.result
  })
}
// 任务类型选择
const getTaskTypeClick = (x) => {
  form.businessTaskType = x.itemValue
  form.businessTaskTypeName = x.itemText
}
// 获取工序 产线 位置列表
const getRuleList = (e, type) => {
  // if (!showDetail.value) {
  if (type === '1') {
    //获取工序
    if (perationList.value?.length === 0) {
      fetchProcess({
        type: type,
        parentCode: '',
        scanType: '',
      }).then((res) => {
        perationList.value = res.result.list
      })
    }
  } else if (type === '2') {
    if (tableList.value[e.seq].processCode !== '') {
      fetchProcess({
        type: type,
        parentCode: tableList.value[e.seq].processCode,
        scanType: '',
      }).then((res) => {
        console.log(res,'res')
        tableList.value[e.seq].lineList = res.result.list
      })
    }
  } else if (type === '3') {
    if (tableList.value[e.seq].lineCode !== '') {
      fetchProcess({
        type: type,
        parentCode: tableList.value[e.seq].lineCode,
        scanType: '',
      }).then((res) => {
        tableList.value[e.seq].locationList = res.result.list
      })
    }
  }
}
const getRuleClick = (e, type) => {
  // if (!showDetail.value) {
  perationList.value.forEach((item) => {
    if (item.code === e.processCode) {
      tableList.value[e.id].processName = item.text
    }
  })
  tableList.value[e.id].lineList.forEach((item) => {
    if (item.code === e.lineCode) {
      tableList.value[e.id].lineName = item.text
    }
  })
  if (type === '3') {
    let index = tableList.value[e.id].locationList.findIndex((item) => item.code === e.locationCode)
    tableList.value[e.id].locationName = tableList.value[e.id].locationList[index].text
    tableList.value[e.id].code = e.locationList[index]?.point
    tableList.value[e.id].wareType = e.locationList[index]?.cartonType
    tableList.value[e.id].currentQty = e.locationList[index]?.qty
    if (e.id == 0) {
      tableList.value[e.id].operation = 'COLLECT'
    } else if (e.id == 1) {
      tableList.value[e.id].operation = 'DELIVERY'
    }
  }
  // }
}
//点击提交
const handleCreateClick = () => {
  submitForm(dataFormRef.value,dataFormRef2.value,dataFormRef3.value)
}
// 取消任务
const handleCancel = () => {
  let parmes = {
    taskCode: detailData.value.taskCode,
  }
  cancelTaskByTaskCode(parmes).then((res) => {
    if (res.code == '400') {
      useMessage().warning(res.message)
    } else if (res.code == '200') {
      useMessage().success(t('agv.cancelSucceeded'))
      handleCancelClick()
      getdataList()
    }
  })
}
// 修改优先级
const handleChangePriority = () => {
  changePriorityRef.value.openDialog(detailData.value)
}
const handleLocation = () => {
  let index = tableList.value.findIndex((item) => item.operation == 'DELIVERY')
  tableList.value[index].edit = true
  changeLocation.value = true
}
const handleChange = () => {
  let parmes = {
    taskCode: detailData.value.taskCode,
    taskstep: tableList.value[1],
  }
  modifyTaskLocation(parmes).then((res) => {
    if (res.code == 200) {
      useMessage().success(t('agv.modifySuccessfully'))
    } else {
      useMessage().error(res.message)
    }
    tableList.value[1].edit = false
    changeLocation.value = false
  })
}
// 关闭弹框
const handleCancelClick = () => {
  tableList.value = [
    {
      id: 0,
      edit: false,
      seq: 0,
      code: '', //点位
      processCode: '', //工序code
      processName: '', //工序名称
      lineCode: '',
      lineName: '',
      locationCode: '',
      locationName: '',
      operation: '', //操作类型
      wareType: '', //货物类型
      currentQty: 0, //数量
      qty: 1, //目的地存在数量
      lineList: [], //产线列表
      locationList: [], //位置列表
    },
    {
      id: 1,
      edit: false,
      seq: 1,
      code: '',
      processCode: '',
      processName: '',
      lineCode: '',
      lineName: '',
      locationCode: '',
      locationName: '',
      operation: '',
      wareType: '',
      currentQty: 0,
      qty: 1,
      lineList: [],
      locationList: [],
    },
  ]
  tableList.value[1].edit = false
  dataFormRef.value?.resetFields()
  // detailList.value = [];
  isWait.value = false
  visible.value = false
  changeLocation.value = false
}
// 打开弹框
const openAddDialog = (e) => {
  visible.value = true
  showDetail.value = false
  if (e) {
    showDetail.value = true
    detailData.value = e
    const lang = localStorage.getItem('lang')
    let obj = {
      taskCode: e.taskCode,
      lang,
    }
    fetchTaskDetail(obj).then((res) => {
      tableList.value.forEach((listItem) => {
        res.result.forEach((detailItem) => {
          if (listItem.seq === detailItem.seq) {
            listItem.code = detailItem.code
            listItem.processCode = detailItem.processCode
            listItem.processName = detailItem.processName
            listItem.lineCode = detailItem.lineCode
            listItem.lineName = detailItem.lineName
            listItem.locationCode = detailItem.locationCode
            listItem.locationName = detailItem.locationName
            listItem.operation = detailItem.operation
            listItem.wareType = detailItem.wareType
            listItem.currentQty = detailItem.currentQty
            listItem.qty = detailItem.qty
          }
        })
      })
    })
  }
  if (e?.taskStatusStr === '等待步骤执行') {
    isWait.value = true
  }
}
// 暴露变量
defineExpose({
  openAddDialog,
})
</script>
<style scoped lang="scss">
.box-card {
  padding-left: 50px;
  margin-bottom: 30px;

  .el-row {
    height: 30px;
    line-height: 30px;
  }
}

 :deep(.el-form-item .el-input ) {
  width: 100% !important;
}

 :deep(.el-form-item .el-select) {
  width: 100% !important;
}


</style>
